#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

//98.46 %
class Solution
{
  public:
	int minSubArrayLen(int s, vector<int> &nums)
	{
		int l = 0, r = -1;
		int sum = 0;
		int len = nums.size() + 1;
		while (l < nums.size())
		{
			if (sum < s && r + 1 < nums.size())
				sum += nums[++r];
			else
				sum -= nums[l++];
			if (sum >= s)
				len = min(len, r - l + 1);
		}
		if (len == nums.size() + 1)
			return 0;
		return len;
	}
};

int main()
{
	int arr[6] = {2, 3, 1, 2, 4, 3};
	vector<int> myVector(arr, arr + 6);
	cout << Solution().minSubArrayLen(7, myVector) << endl;
	return 0;
}
